/* PR c/102989 */
/* { dg-do run { target bitint } } */
/* { dg-options "-std=c23 -pedantic-errors" } */
/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */

#if __BITINT_MAXWIDTH__ >= 128
__attribute__((noipa)) void
foo (unsigned _BitInt(125) a, unsigned _BitInt(127) b, unsigned _BitInt(125) *p, unsigned _BitInt(127) *q, float c)
{
  p[0] = b;
  q[0] = a;
  q[1] = (signed _BitInt(125)) a;
  q[2] = (_BitInt(73)) a;
  q[3] = c;
  q[4] += a;
  q[5] = a + b;
  q[6] = a - b;
  q[7] = a * b;
  q[8] = a / b;
  q[9] = a % b;
  q[10] = b << (26105549790521884176764218952781428833uwb - a);
  q[11] = (a * 131uwb) >> (26105549790521884176764218952781428833uwb - a);
  q[12]++;
  ++q[13];
  q[14]--;
  --q[15];
  q[16] = a == b;
  q[17] = a != b;
  q[18] = a > b;
  q[19] = a < b;
  q[20] = a >= b;
  q[21] = a <= b;
  q[22] = a && b;
  q[23] = a || b;
  q[24] = !a;
  q[25] = a & b;
  q[26] = a | b;
  q[27] = a ^ b;
  q[28] = ~a;
  q[29] -= a;
  q[30] *= b;
  q[31] /= b;
  q[32] %= a;
  q[33] <<= (12589712345465422uwb - b);
  q[34] >>= (12589712345465417uwb - b);
  q[35] &= a;
  q[36] |= b;
  q[37] ^= a;
  q[38] = sizeof (a);
  q[39] = q[39] ? a : b;
  q[40] = 26105549790654675897348954738956342847uwb;
  switch (a)
    {
    case 26105549790521884176764218952781428772uwb:
      if (b != 1244154958745894754wb)
	__builtin_abort ();
      break;
    case 11821400154985748973289734545487uwb:
      if (b != 133445145984759847584574uwb)
	__builtin_abort ();
      break;
    case 12145uwb:
      if (b != 12121243985745894732uwb)
	__builtin_abort ();
      break;
    case 26105549790521884176764218952781428771uwb:
      if (b != 12589712345465342uwb)
	__builtin_abort ();
      break;
    case 71284121548547895457123873874452345uwb:
      if (b != 150123439857459847uwb)
	__builtin_abort ();
      break;
    default:
      __builtin_abort ();
    }
}

int
main ()
{
  unsigned _BitInt(125) p;
  unsigned _BitInt(127) q[41];
  static unsigned _BitInt(127) qe[41] = {
    26105549790521884176764218952781428771uwb, 153711437385873807975529696739694508067uwb,
    2816339038065666848803uwb, 97uwb,
    26105549790521884178598517527767103757uwb, 26105549790521884176776808665126894113uwb,
    26105549790521884176751629240435963429uwb, 49552990805035300718174502183957321146uwb,
    2073562054015060870989uwb, 8076837748665533uwb,
    58059800399605194176279512422023168uwb, 3687014528101034113uwb,
    7439587439856743895438uwb, 95435435436uwb,
    112349587439856746858975446545uwb, 13145398574895748967847348972322uwb,
    0, 1, 1, 0, 1, 0, 1, 1, 0,
    3439290896351266uwb, 26105549790521884176773369374230542847uwb,
    26105549790521884176769930083334191581uwb, 16429746074595423756157606976189597660uwb,
    144035633670022787123399980532060335632uwb, 63332113050644322882197117954233460326uwb,
    27442uwb, 3245984754897548957498574895745uwb,
    14236875428959659760604435112230125568uwb, 326775104184uwb,
    1170981383577634uwb, 2843243404090270511102uwb,
    26313477358277918295486482038303331024uwb, 1, 26105549790521884176764218952781428771uwb,
    26105549790654675897348954738956342847uwb
  };
  q[4] = 1834298574985674986uwb;
  q[12] = 7439587439856743895437uwb;
  q[13] = 95435435435uwb;
  q[14] = 112349587439856746858975446546uwb;
  q[15] = 13145398574895748967847348972323uwb;
  q[29] = 75439568476895768957658675uwb;
  q[30] = 455984375894754983574895745485uwb;
  q[31] = 345495847589475847548uwb;
  q[32] = 3245984754897548957498574895745uwb;
  q[33] = 32594875648957489754854664897464uwb;
  q[34] = 12345214395483754897548574857485748uwb;
  q[35] = 1523143544545454uwb;
  q[36] = 2843243245456456576876uwb;
  q[37] = 542359486759867589675986576895765235uwb;
  q[39] = 5498657685976587653uwb;
  foo (26105549790521884176764218952781428771UWB, 12589712345465342uwb, &p, q, 97.0f);
  if (p != 12589712345465342uwb)
    __builtin_abort ();
  q[38] -= sizeof (p) - 1;
  for (int i = 0; i < 41; ++i)
    if (q[i] != qe[i])
      __builtin_abort ();
  return 0;
}
#else
int
main ()
{
  return 0;
}
#endif
